package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

public class Register extends AppCompatActivity {
    private EditText etRegUsername;
    private EditText etRegPassword;
    private RadioButton rbMale;
    private RadioButton rbFemale;
    private EditText etRegAge;
    private Button btnRegSubmit;
    private Button btnRegCancel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_regisit);

        etRegUsername = (EditText) findViewById(R.id.et_reg_username);
        etRegPassword = (EditText) findViewById(R.id.et_reg_password);
        rbMale = (RadioButton) findViewById(R.id.rb_male);
        rbFemale = (RadioButton) findViewById(R.id.rb_female);
        etRegAge = (EditText) findViewById(R.id.et_reg_age);
        btnRegSubmit = (Button) findViewById(R.id.btn_reg_submit);
        btnRegCancel = (Button) findViewById(R.id.btn_reg_cancel);

    }

    public void cancel(View view) {
        Intent intent = new Intent(this, Login.class);
        setResult(RESULT_CANCELED,intent);
        finish();
    }

    public void register(View view) {
        String username=etRegUsername.getText().toString();
        String password=etRegPassword.getText().toString();
  int age= Integer.parseInt(etRegAge.getText().toString());
        boolean gender=rbMale.isChecked();
        String prefName ="com.example.myapplication";

        SharedPreferences sharedPreferences =getSharedPreferences(prefName,MODE_PRIVATE);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putString("username"+username,username);
        edit.putString("password"+username,password);
        edit.putBoolean("gender"+username,gender);
        edit.putInt("age"+username,age);
        edit.apply();
        Intent intent = new Intent(this, Login.class);
        intent.putExtra("username",username);
        intent.putExtra("password",password);
        setResult(RESULT_OK,intent);
        finish();
    }
}